<? 
	if(isset($_POST['btnsubmit']))
	{
		require("required/dbconnect.php");
		require("../required/email.php");
		
		$dv_id=$_POST['dv_id'];
		
		$member_id=$_POST['hidid'];
		
		email_discount_voucher($member_id,$dv_id);
		
		header("Location:member_viewfull.php?action=4&id=$member_id");
	}
	
	$title="View all products"; 
	$pageid="1";
	$accessid="a00";
	
	require("required/dbconnect.php"); 
	require("required/function.php");
	require("required/header.php");
	
	checkAccess("allow_gift_management",1);
	
?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?

		
	if(!empty($_GET['action']))
	{
		switch($_GET['action'])
		{
			case 1:
				$msg="<div class='dw_success'>Data Added!</div>";
				break;
			case 2:
				$msg="<div class='dw_failed'>Voucher code already exist,update failed!</div>";
				break;
			case 3:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;	
			default:
				$msg="";
				break;
		}
		echo "<script>displayMsg('divMsg')</script>";	
	}else{
		$msg="";
	}
	$id=$_GET['id'];
	$get_id=mysql_query("select * from os_member where id=$id");
	
	
	$get_dv=mysql_query("select * from os_discount_voucher where is_birthday_voucher=0")or die(mysql_error());
	
	
?>
<table width="100%">


<td align="left" valign="top">
	<div class="title"><?= $title ?></div>
	    <div id="divMsg"><?= $msg ?></div>
    <table width="100%" cellpadding="2" cellspacing="1">
		<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm1">
        <tr>
        	<td>Send discount voucher to  </td>
            <td>:</td>
            <Td><?= mysql_result($get_id,0,"name"); ?></Td>
        </tr>
        <tr>
        	<td>Select Discount Voucher</td>
            <td>:</td>
			<td>
            	<select name="dv_id">
                	<option value="">Please select</option>
					<?
                        while($v=mysql_fetch_array($get_dv))
                        { 
							if($v['discount_type']=="P")
							{
								$desc=number_format($v['discount_amount'],0)."% off";
								
							}
							else
							{
								$desc=" RM".$v['discount_amount']." off";
								
							}
							       
                    ?>	
					<option value="<?= $v['id'] ?>"><?= $v['voucher_name'] ?> - <?= $v['voucher_code'] ?> (  <?= $desc ?>, <?= $v['times_to_use'] ?> time(s) to use)</option>		                      
                    <? 
						} 
					?>
              </select>
           </td>
       </tr>
	</table>
    <input type="hidden" value="<?= $id ?>" name="hidid"/>
    <input type="submit	" value="Send" name="btnsubmit" onclick="return confirm('Confirm to continue?')"/>
    <input type="button	" value="Back" onclick="window.open('member_viewfull.php?id=<?= $id ?>','_self')"/>
	</td>
    </form>
</table>

<? require("required/footer.php"); ?>

